﻿@using System.Globalization
@using LERP.Domain.Enums
@using LERP.Web.App_Start
@using LERP.Web.Controllers
@using Sharp.Framework
@using Sharp.Framework.Extensions

@model MvcContrib.Pagination.IPagination<LERP.Web.Controllers.ViewModels.ReturnOrderViewModels.ReturnOrderListViewModel>
@{
    ViewBag.Title = "退单统计";
    Layout = "~/Views/Shared/_Layout.cshtml";

    var total = ViewBag.Total as ReturnOrderTotal;
}

@using (Html.BeginForm("Count", "ReturnOrder", FormMethod.Get))
{ 
    <table class="table_input" style="width: 100%;">
        <tr>

            <th style="width: 15%;">员工:</th>
            <td style="width: 35%;">
                @Html.DropDownList("userId", (ViewBag.Users as List<SelectListItem>).InsertEmpty(), new { @class = "text-medium" })
            </td>


            <th style="width: 15%;">客户:</th>
            <td>
                @Html.TextBox("customerName", Request.QueryString["customerName"], new { @class = "text-medium", @readonly = "readonly", style = "width: 99%;" })

                @Html.Hidden("customerType", Request.QueryString["customerType"])
                @Html.Hidden("customer", Request.QueryString["customer"])
            </td>
            <td style="width: 30px;"><a href="@Url.Action("Select", "Customer", new { all = true })" id="customer_select" style="">选择</a></td>
            <td style="width: 30px;"><a href="javascript:void();" id="customer_noselect" style="">取消</a></td>
        </tr>
        <tr>
            <th>状态:</th>
            <td colspan="4">
                @{
                    var status = Request.QueryString["status"];
                    var selects = new List<int>();
                    if (!string.IsNullOrEmpty(status))
                    {
                       selects= status.Split(',').Select(x => int.Parse(x)).ToList();
                    }
                    if (!selects.Any())
                    {
                        selects.Add((int) ReturnOrderStatus.Close);
                    }
                    foreach (var item in ReturnOrderStatus.Close.ToDictionary())
                    {

                        <input type="checkbox" @(selects.Contains(item.Value) ? "checked=\"checked\"" : "")  name="status" id="status_@item.Value" value="@item.Value"/>
                        <label for="status_@item.Value">@item.Key</label>
                    }
                }
                

            </td>
        </tr>
        <tr>


            <th>年月:</th>
            <td>
                @Html.TextBox("month", "", new { @class = "text-medium", title = "格式:201304" })
            </td>
            <td colspan="3" style="text-align: right;">
                <input type="submit" class="button-submit" value="统计" />
            </td>
        </tr>

    </table>
             
}
@if (Model != null && Model.Any())
{
    <table class="table_list" style="width: 99%;">
        <tr>
            <th style="width: 80px;">退单编码</th>
            <th>客户</th>
            <th style="width: 80px;">金额</th>
            <th style="width: 50px;">状态</th>
            <th style="width: 100px;">退单日期</th>
        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td>@Html.ActionLinkEx(item.Id.ToString(CultureInfo.InvariantCulture), "Details", "ReturnOrder", new { id = item.Id, returnUrl = Request.RawUrl }, new { @class = "" })</td>
                <td>@item.Customer</td>
                <td>@item.Amount</td>
                <td>@item.Status.GetDescription()</td>
                <td>@item.ReturnDate.ToString("yyyy年MM月dd日")</td>
            </tr>
        }
        <tr>
            <td colspan="5">
                <table>
                    <tr>
                        <td style="border-width: 0px">退单数:</td>
                        <td style="border-width: 0px">@total.Count</td>
                        <td style="border-width: 0px">退单金额:</td>
                        <td style="border-width: 0px">@total.AmountSum</td>
                        <td style="border-width: 0px">退单出仓金:</td>
                        <td style="border-width: 0px">@total.WarehouseAmountSum</td>
                    </tr>
                </table>


            </td>
        </tr>
    </table>

    <div class="page">
        @Html.Pager("page", Model.PageSize, Model.TotalItems)
    </div>
}
else
{
    <div class="empty">
        查询信息为空
    </div>
}
@section Scripts {
    <script type="text/javascript">

        $(function () {
            //选择客户
            $("#customer_select").click(function () {
                var iTop = (window.screen.availHeight - 30 - 600) / 2; //获得窗口的垂直位置;
                var iLeft = (window.screen.availWidth - 10 - 750) / 2; //获得窗口的水平位置;
                var url = this.href;
                window.open(url, "选择客户", "height=600, width=750, toolbar=no, menubar=no, resizable=no, location=no, status=no,scrollbars=yes" + ',top=' + iTop + ',left=' + iLeft);
                return false;
            });
            //取消选择客户
            $("#customer_noselect").click(function () {
                document.getElementById("customer").value = "";
                document.getElementById("customerName").value = "";
                document.getElementById("customerType").value = "";
                return false;
            });
            $(":checkbox[name='status']").click(function () {
                if ($(":checked[name='status']").length==0) { 
                    return false;
                }
            });

        })

    </script>

}
